Ext.define('Era.controller.EventForm',{
    extend: 'Ext.app.Controller',
    models: ['Event'],
    stores: ['Events'],
    views: ['EventForm','IconField'],
 
    init: function() {
        this.control({
            'button[action=submit]': {
              click: this.onSubmit  
            },
            'button[action=cancel]': {
                click: this.onCancel
            },
            'iconfield': {
                render: this.onIconRender
            }
        });
    },
    
    onSubmit: function(button) {
        
        //get a reference to the form and the form data
        var form_panel = button.up('eventform');
        var form_data = form_panel.down('form').getForm();
        
        //update form values in the record
        var record = form_data.getRecord();
        form_data.updateRecord(record);

        //save or update the event
        var store = this.getStore('Events');
        if (record.phantom != null && record.phantom == true) {
            store.add(record);
        } else {
            store.update(record);
        } 

        form_panel.hide();
    },
        
    onCancel: function(button) {
       
        //get a reference to the form and the form data
        var form_panel = button.up('eventform');
        
        form_panel.hide();
    },
    
     onIconRender: function(component) {
         
        component.getEl().on('click',function() {
            Ext.Msg.alert('Choose a picture placeholder');
        });
        
    }
    
    
});